﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="View.aspx.cs" Inherits="JKF.Web.Customer.Customer_View" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <%= RegScript("~/js/jquery.1.5.js")%>
    <%= RegScript("~/js/jquery.nhis.js")%>
    <%= RegScript("~/js/jquery.rchis.js")%>
    <%= RegScript("~/js/jquery-ui-custom.min.js")%>
    <%=RegScript("~/js/jquery.json.js")%>
    <%= RegScript("~/js/css.js")%>
    <%= RegScript("~/js/DatePicker/WdatePicker.js")%>
    <%= RegScript("~/js/Common.js")%>
    <%= RegScript("~/js/Jquery.commonGrid.js")%>
    <%=this.RegStyle("~/App_Themes/Theme2/Include.css")%>
    <%= RegScript("~/js/jquery-form.js") %>
    <script type="text/javascript">
        var AppPath = '<%=AppPath %>';
        var handler = AppPath + '/do/Customer/Customer.do';
        var shops = <%=Shops%>;
        var tmpl = new DTemplate();
        var PageSize = 20;
        var pager = null;
        var advSearch = null;
        var exrpot = 0;
        var rowTemplate = "<tr pk=\"${CUSTOMER_KEY}\"><td><input type=\"button\" class=\"op-edit common_btn_edit mr12\" style=\"display:<%=DispEdit%>\"/><input type=\"button\" class=\"op-del common_btn_del mr12\"  style=\"display:<%=DispDelete%>\"/><input type=\"button\" class=\"op-card mr12 btn_style\" value=\"换卡\" style=\"display:<%=ChangeCardDisp%>\"/><input type=\"button\" class=\"op-view mr12 btn_style\" value=\"浏览\"/></td><td>${CARD_NO}</td><td>${NAME}</td><td>${MOBILE}</td><td>${LEVEL_NAME}</td><td>${GROUP_NAME}</td><td>${BIRTHDAY}</td><td>${GIVE_POINTS}</td><td>${CONSUME_POINT}</td><td>${STATUS_NAME}</td><td>${DATE_CREATE}</td><td>${SHOP_NAME}</td></tr>";
        $(function () {
            pager = $('#divPager').pager(AppPath, handler, function () {
                return (advSearch == null || advSearch == undefined) ? {
                    ActionName: 'GetCustomers', dateStart: "", dateEnd: "",
                    ownShop: $.FxNull($("#ownShop").attr("codes"), ""),
                    field: $('#filterBy').val(),
                    fieldOp: $("#filterOperater").val(),
                    fieldKey: $.trim($("#fiterText").val())
                } : {
                    ActionName: 'GetCustomerAdv',
                    advOptions: $.toJSON(advSearch)//,
                    //isExport:exrpot
                };
            }, function (data) {
                var tbody = $('#tb tbody');
                tbody.empty();
                if (data && data.Entity && data.Entity.length) {
                    tbody.html(tmpl(rowTemplate, data.Entity, true));
                } else {
                    tbody.html('<tr><td colspan="11" style="text-align: center">没有数据!</td></tr>');
                }
                $("#tb").H8_Grid($("#divPager"), (function (){var tbHeight = $(window).height()-35; tbHeight-=($(".common_search").size()>0)?$(".common_search").eq(0).height():0; tbHeight-=($("#divPager").size()>0)?$("#divPager").height():0; return tbHeight < 300 ? 300 : tbHeight;})());
            }, PageSize, true);
            BindGridEvent();
            //Customer_Edit.aspx

            $('#btnSearch').click(function () {
                advSearch = null;
                $("#advCondition").text("").attr("title","");
                pager.option.pageIndex = 1;
                pager.getPegerData();
                return false;
            });
            $("#btnAdvanceSearch").click(function () {
                top.pop("高级搜索", '<%= ResolveUrl("~/Customer/AdvancedSearch.aspx") %>', 800, 450, function (rslt) {
                    advSearch = rslt;
                    var msg=GetAdvancedSearchInfo(rslt);
                    if(msg.length>0) {
                        $("#advCondition").text("高级条件："+(msg.length > 50 ? msg.substring(0, 50) : msg)).attr("title", msg);
                    }
                    pager.option.pageIndex = 1;
                    pager.getPegerData();
                });
            });
            
            $("#ownShop").MgrShopSelect(AppPath,shops);

            $("#btnExport").click(function() {
                var obj = (advSearch == null || advSearch == undefined) ? {
                    ActionName: 'GetCustomers',
                    dateStart: "",
                    dateEnd: "",
                    ownShop: $.FxNull($("#ownShop").attr("codes"), ""),
                    field: $('#filterBy').val(),
                    fieldOp: $("#filterOperater").val(),
                    fieldKey: $.trim($("#fiterText").val()),
                    isExport:1,
                    PageIndex:pager.option.pageIndex ,
                    PageSize:pager.option.pageSize
                } : {
                    ActionName: 'GetCustomerAdv',
                    advOptions: $.toJSON(advSearch),
                    isExport:1,
                    PageIndex:pager.option.pageIndex ,
                    PageSize:pager.option.pageSize
                };
                $.formP(handler, obj);
            });
        });
        function BindGridEvent() {
            $(':button.op-del').live('click', function () {
                if (!confirm("确认删除吗?")) return false;
                var tr = $(this).parent().parent();
                $.post(handler, { ActionName: 'RemoveCustomer', customerKey: tr.attr('pk') }, function (obj) {
                    if (!obj.Success) alert(obj.Message);
                    else {
                        reduceCount();//减少记录总条数
                        tr.remove();}
                }, "json");
            });
            $(':button.op-edit').live('click', function () {
                window.parent.pop("编辑顾客", '<%= ResolveUrl("~/Customer/Customer_Edit.aspx?customerKey=") %>' + $(this).parent().parent().attr("pk"), 830, 500, updateList);
            });
            $(':button.op-view').live('click', function () {
                window.parent.pop("顾客信息", '<%= ResolveUrl("~/Customer/Customer_InfoViewer.aspx?customerKey=") %>' + $(this).parent().parent().attr("pk"), 830, 500, updateList);
            });
            $(":button.op-card").live('click', function () {
                window.parent.pop("换卡", '<%= ResolveUrl("~/Customer/Customer_Edit.aspx?module=changecard&customerKey=") %>' + $(this).parent().parent().attr("pk"), 830, 500, updateList);
            });
        }

        //弹出层
        function Add(id) { window.parent.pop("添加顾客", '<%= ResolveUrl("~/Customer/Customer_Add.aspx?customerKey=") %>' + id, 830, 500, updateList); };

        function Import(){ window.parent.pop("导入顾客", '<%= ResolveUrl("~/Customer/Import.aspx") %>', 830, 500, updateList); };

        function updateList(obj) {
            var tbody = $('#tb tbody');
            if (tbody.find("tr[pk]").size() == 0) tbody.empty();
            var key = $.FxNull(obj.CUSTOMER_KEY, "");
            if (key == "") return;
            var editRow = tbody.find("tr[pk='" + key + "']");
            var newRow = $(tmpl(rowTemplate, obj, true));
            if (editRow.size() == 0) {
                tbody.prepend(newRow);
                addCount(); //添加成功之后更新记录总条数
            } else {
                newRow.insertAfter(editRow);
                editRow.remove();
            }
            $("#tb").H8_Grid($("#divPager"), (function (){var tbHeight = $(window).height()-35; tbHeight-=($(".common_search").size()>0)?$(".common_search").eq(0).height():0; tbHeight-=($("#divPager").size()>0)?$("#divPager").height():0; return tbHeight < 300 ? 300 : tbHeight;})());
            BindGridEvent();
        }
        
        function GetAdvancedSearchInfo(srchObj){
            var conditions=[];
            if($.FxNull(srchObj.CARD_NO,"")!="") conditions.push("卡号:"+srchObj.CARD_NO);
            if($.FxNull(srchObj.LEVEL_NAME,"")!="") conditions.push("顾客级别:"+srchObj.LEVEL_NAME);
            if($.FxNull(srchObj.NAME,"")!="") conditions.push("姓名:"+srchObj.NAME);
            if($.FxNull(srchObj.SEX,"")!="") conditions.push("性别:"+(srchObj.SEX=="0"?"男":"女"));
            if($.FxNull(srchObj.REFEREE_CARD,"")!="") conditions.push("推荐人卡号:"+srchObj.REFEREE_CARD);
            if($.FxNull(srchObj.REFEREE,"")!="") conditions.push("推荐人姓名:"+srchObj.REFEREE);
            if($.FxNull(srchObj.ID_CARD,"")!="") conditions.push("身份证:"+srchObj.ID_CARD);
            if($.FxNull(srchObj.AGEFROM,"")!="" || $.FxNull(srchObj.AGETO,"")!="") conditions.push("年龄:"+srchObj.AGEFROM+"  至  "+srchObj.AGETO);
            if($.FxNull(srchObj.MOBILE,"")!="") conditions.push("手机号:"+srchObj.MOBILE);
            if($.FxNull(srchObj.PHONE,"")!="") conditions.push("电话:"+srchObj.PHONE);
            if($.FxNull(srchObj.TITLE,"")!="") conditions.push("职业:"+srchObj.TITLE);
            if($.FxNull(srchObj.FAMILY,"")!="") conditions.push("家庭情况:"+srchObj.FAMILY);
            
            if($.FxNull(srchObj.PROVINCE,"")!="") conditions.push("所在省:"+srchObj.PROVINCE_NAME);
            if($.FxNull(srchObj.CITY,"")!="") conditions.push("所在市:"+srchObj.CITY_NAME);
            if($.FxNull(srchObj.AREA_CODE,"")!="") conditions.push("所在区:"+srchObj.AREA_NAME);
            
            if($.FxNull(srchObj.DATE_CREATESTART,"")!="" || $.FxNull(srchObj.DATE_CREATEEND,"")!="") conditions.push("注册日期:"+srchObj.DATE_CREATESTART+"  至  "+srchObj.DATE_CREATEEND);
            if($.FxNull(srchObj.AVAPOINTFROM,"")!="" || $.FxNull(srchObj.AVAPOINTTO,"")!="") conditions.push("可用积分:"+srchObj.AVAPOINTFROM+"  至  "+srchObj.AVAPOINTTO);
            if($.FxNull(srchObj.BIRTHDAYFROM,"")!="" || $.FxNull(srchObj.BIRTHDAYTO,"")!="") conditions.push("生日:"+srchObj.BIRTHDAYFROM+"  至  "+srchObj.BIRTHDAYTO);
            if($.FxNull(srchObj.GROUP_NAME,"")!="") conditions.push("顾客分组:"+srchObj.GROUP_NAME);
            return conditions.join(" + ");
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div class="warrper_body">
            <div class="index">
                <div class="common_search">
                    <div class="l_h45">
                        <span class="mr30 mb20">查询项：
                        <select id="filterBy" class="common_search_select w70">
                            <option value="CARD_NO">卡号</option>
                            <option value="NAME">姓名</option>
                            <option value="LEVEL_CODE">级别</option>
                            <option value="MOBILE">手机号</option>
                        </select>
                            <select id="filterOperater" class="common_search_select w70">
                                <option value="like">包含</option>
                                <option value="=">=</option>
                            </select>
                            <input id="fiterText" type="text" class="common_search_input w100" />
                        </span><span class="mr30 mb20">所属店铺：
                        <input type="button" id="ownShop" class="common_btn_gaoji115" />
                        </span>
                        <input id="btnSearch" type="button" value="" class="common_btn_search" />
                        <input id="btnAdd" type="button" value="" onclick="Add()" class="common_btn_add2"
                            style="display: <%=DispAdd%>;" />
                        <input type="button" id="btnExport" value="导出Excel" class="btn_style" />
                        <input type="button" id="btnImport" value="导入" class="btn_style" onclick="Import();return false;" />
                        <input id="btnAdvanceSearch" type="button" value="" class="common_btn_gaoji" />
                        <span id="advCondition"></span>
                    </div>
                </div>
                <div class="l_h7">
                </div>
                <div class="index_table">
                    <table id="tb" class="common_table">
                        <thead>
                            <tr>
                                <th width="200px" orderaction="false">操作
                                </th>
                                <th width="100px" ordertype="string">卡号
                                </th>
                                <th width="150px" ordertype="string">姓名
                                </th>
                                <th width="140px" ordertype="string">手机
                                </th>
                                <th width="100px" ordertype="string">级别
                                </th>
                                <th width="100px" ordertype="string">顾客分组
                                </th>
                                <th width="100px" ordertype="string">生日
                                </th>
                                <th width="100px" ordertype="string">可用体验积分
                                </th>
                                <th width="100px" ordertype="string">消费积分</th>
                                <th width="100px" ordertype="string">顾客状态
                                </th>
                                <th width="160px" ordertype="string">登记时间
                                </th>
                                <th width="100px" ordertype="string">所属店铺
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td colspan="11" style="text-align: center">点击搜索查看数据
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div class="page" id="divPager">
                </div>
            </div>
        </div>
    </form>
</body>
</html>
